package org.example.my.service;

import org.example.my.Utility.SecurityUtil;
import org.example.my.mapper.BlogMapper;
import org.example.my.mapper.UserMapper;
import org.example.my.model.Result;
import org.example.my.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    BlogMapper blogMapper;

    public UserInfo selectUserInfoByUserName(String userName) {
        return userMapper.selectUserInfoByUserName(userName);
    }

    public UserInfo selectUserInfoById(Integer userId) {
        return userMapper.selectUserInfoById(userId);
    }

    public Boolean isLogin(String password, UserInfo userInfo) {
        return SecurityUtil.checkPassword(password, userInfo.getPassword());
    }

    public Integer getBlogCountByUserid(String userName) {
        Integer userId = userMapper.selectIdByUserName(userName);
        return blogMapper.selectBlogCount(userId);
    }

    public Integer insertUser(UserInfo userInfo) {
        return userMapper.insertUser(userInfo);
    }
}
